#ifndef TEMP_H
#define TEMP_H

#include <vector>
#include "Global.h"


class Temp {
public:

    Temp();
    int temper(bool iosym, int nrchl,
            int mw, int nw, int ndt, double dt, int
            iprint, int *idt, int istem, double temgrd, double *
            dtemgrd, int iwn, double tempgrd, double *dtempgrd);


    double cieprzem(double dt, double t, double crate,
            double time, double *tip0, double *xvv);

    int savetem(int *mdt, int *idt, double tchcr, int mw, int nw);

    int setval(double *tp, int nw, int iw, int iwn);

    int setvl(double *x, double *y, double *xn,
            double *yn, double *valx, double *valy, double *valxn,
            double *valyn, int nw, int iw, int iwn);

    double odlg(int *num, double *x, double *y, double x0, double y0);

    int interp(double *x, double *y, double *u,
            double *xx, double *yy, double *uu, int ij);

    int elem(bool iosym, int nel, int it, int
            *iw, double rlchar, double *dysyp, double dt, int *
            npas1, int *ij, int *ji, int qq);

    int dkod(int kod, int *ikod, int *kkod);
    int fmatb(double *xww, double ksi, double eta,
            double *bx, double *by, double *n, double *detj);

    std::vector<std::vector<double> > v_plg;
    std::vector<std::vector<double> > v_tlg;

    void AddT(const std::vector<double>& t);
    void AddTFinal();
    void AddTchcal(double val);
    void ShowTemps(bool val);

    int putemp(int iwn, double *tp, double tchcal, int iw, int nw, double tempgrd, double *dtempgrd);
    int putem(int istem, double *f, const std::vector<double>& tp, double tchcal, int *nstem, double temgrd, double *dtemgrd);


    std::vector<double> v_tchcal;

    std::vector<bool> v_show_temps;

    std::vector<std::vector<double> > v_t;
    std::vector<std::vector<double> > v_tf;

private:
    
        struct t_temhist {
        double temhist[MWMAX * NWMAX][ILDTMAX], temlast[MWMAX * NWMAX];
        int ildt, iidt;
    } temhist;

    double epsilon;
    double f[MWMAX * NWMAX];
    double h[(NWMAX + 2)*(MWMAX * NWMAX)];
    double hh[(NWMAX + 2)*(MWMAX * NWMAX)];            // TODO - tymczasowa zmienna
    double hcf[24 * (MWMAX - 1)*(NWMAX - 1)];
    double c[(NWMAX + 2)*(MWMAX * NWMAX)];
    double cnd[24 * (MWMAX - 1)*(NWMAX - 1)];
    double crate[MWMAX * NWMAX];
    
    int fn(double ksi, double eta, double *n);
    int ilo(double *a, double *b, int n, int nm, int m, double *c);
    //int ilo(double *a, double *b, int n, int nm, int m, double *c);

    int alrola(double tsr, double *lambda, double *ro, double *cp);
    int alspray(double t, double *l, double *razpr, double *alfa, double *alfa1);
    int alrol1(double *tsr, double l, double razpr, double *alfa, double *alfa1);

    //int gauss1(int nn, int mm, double a[][MWMAX*NWMAX]);
    int gauss1(int nn, int mm, double *a);
    int gauss2(int nn, int mm, double *a, double *b);
    //int gauss1(int nn, int mm, double *a[MWMAX*NWMAX]);
    //int gauss2(int nn, int mm, double a[], double *b);   

    struct t_static {
        double wyzn, a[16] /* bylo [4][4] */;
    } static_;

};


#endif
